const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const router = require('./router.js')
// 启动静态资源访问服务
app.use(express.static('public'))
// 解决跨域问题
app.all('*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header('Access-Control-Allow-Headers', ['Content-Type', 'mytoken']);
  next();
});
//配置body请求参数
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
// 配置路由
app.use(router)
app.listen('3000', () => {
  console.log('服务器创建成功')
})